#include<stdio.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#include<dirent.h>
#include<time.h>

void list(char path[200])
{
	DIR *dirp;
	char filepath[200];
	struct dirent *envdir;
	struct stat buf;

	stat(path, &buf);

	if(S_ISDIR(buf.st_mode))
	{
	//	printf("%d", buf.st_mode);
		dirp = opendir(path);

		while(envdir = readdir(dirp))
		{	

			memset(filepath,0,20);
			strcat(filepath,path);
			strcat(filepath,"/");
			strcat(filepath,envdir -> d_name);
			if(strcmp(envdir -> d_name, ".") == 0 || strcmp(envdir -> d_name, "..") == 0)
			{
				continue;
			}

			stat(filepath, &buf);
			if(S_ISDIR(buf.st_mode))
			{	
				list(filepath);
			}
			else
			{
	//			printf("%d", buf.st_mode);
				printf("path:%s	size:%ld	last time:%s\n", filepath, buf.st_size, ctime(&buf.st_mtime));
			}
		}
		closedir(dirp);
	}
	else
	{
		printf("no dir\n");
	}
}

int main(int argc, char const *argv[])
{
	char path[200] = "/home/ysh/Desktop";

	list(path);

	return 0;
}